﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;
namespace BattleCity
{
    //Defino un delegado
    public delegate void DelegadoBase();

    public class Base : ObjetoPasivo
    {
        private void nada() { }
        public event DelegadoBase BaseDestruida;


        private Base()
        {
            this.Figura = new Rectangulo(new Point(235,460), 30, 30);
            this.energia = 230;
            this.nombre = "Base";
            BaseDestruida += new DelegadoBase(nada);
        }
        private static Base baseOb = null;
        public static Base getBase()
        {
            if (baseOb == null)
            {
                baseOb = new Base();
            }
            return baseOb;
        }
        public static void Reset()
        {
            baseOb = null;
        }

        override public void Daniar(int danio)
        {
            this.energia = this.energia - danio;

            if (this.energia <= 0)
            {
                Escenario.getEscenario().Objetos.Remove(this);
                BaseDestruida();
            }
        }

        override public bool ImpactaCon(Objeto objeto)
        {
            return objeto.ImpactaCon(this);
        }
        override public bool ImpactaCon(Tanque tanque)
        {
            return tanque.ImpactaCon(this);
        }
        override public bool ImpactaCon(Arma arma) { return true; }
        override public bool ImpactaCon(Proyectil proyectil)
        {
            return proyectil.ImpactaCon(this);
        }
        override public bool ImpactaCon(Muro muro) { return true; }
        override public bool ImpactaCon(Base baseob) { return true; }
        override public bool ImpactaCon(Teletransportador bonus) { return true; }

        public override void Persistir(XmlDocument xml, XmlNode subnodo)
        {

            XmlNode principal = xml.CreateElement(this.nombre);
            XmlNode energia = xml.CreateElement("Energia");

            energia.InnerText = Energia.ToString();

            principal.AppendChild(energia);

            subnodo.AppendChild(principal);
        }
    }
}
